package org.skipper.common.constant;

/**
 * 常用错误码Enum定义
 *
 * @author he.wang
 * @since 1.0.2
 */
public enum CommonCodeEnum implements CodeInterface {
    SUCCESS("00000000", "成功"),
    FAIL("00000001", "系统错误"),
    PARAMETER_ERROR("00000002", "参数错误"),
    INVALID_API("00000003", "无效的接口"),
    IP_FORBIDDEN("00000004", "此IP禁止访问"),
    FLOW_CONTROL("00000021", "服务限流"),
    DEGRADE("00000022", "服务降级"),
    PARAM_FLOW_CONTROL("00000023", "热点参数限流"),
    SYSTEM_BLOCK("00000024", "触发系统保护"),
    AUTHORITY_REJECT("00000025", "授权规则不通过"),
    LOW_VERSION_EXCEPTION("20001006", "版本过低, 请及时更新版本"),
    SIGNATURE_INCORRECT("30001001", "签名验证失败"),
    TOKEN_INCORRECT("30001005", "token验证失败"),
    TOAST("31000000", "使用message的内容作为toast提示");

    private String code;
    private String message;

    CommonCodeEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public static String getNameByCode(String code) {
        for (CommonCodeEnum item : CommonCodeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getMessage();
            }
        }
        return null;
    }
}
